package com.java.manage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.common.model.Result;
import com.java.manage.dao.ColorMapper;
import com.java.manage.model.Brand;
import com.java.manage.model.Color;
import com.java.manage.service.ColorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ColorServiceImpl implements ColorService {
    @Autowired
    private ColorMapper colorMapper;

    @Override
    public Result save(Color color) {
        colorMapper.save(color);
        return Result.success();
    }
    @Override
    public Result modify(Color color) {
        colorMapper.modify(color);
        return Result.success();
    }

    @Override
    public Result remove(int[] ids) {
        for (int id : ids) {
            colorMapper.remove(id);
        }
        return Result.success();
    }

    @Override
    public Result list(Color color) {
        PageHelper.startPage(color.getPageNum(), color.getPageSize());
        List<Color> list = colorMapper.list(color);
        PageInfo<Color> pageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();
        map.put("list", pageInfo.getList());
        map.put("total", pageInfo.getTotal());

        return Result.success(map);
    }

    @Override
    public Result get(int id) {
        return null;
    }

    @Override
    public Result colorList() {
        List<Color> colors = colorMapper.colorList();
        return Result.success(colors);
    }
}
